

function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val)
    this.next = (next === undefined ? null : next)
}


/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var middleNode = function (head) {

    let currentNode = head
    let arr = []
    while (currentNode) {
        arr.push(currentNode)
        currentNode = currentNode.next
    }
    let mid = Math.floor(arr.length / 2)
    return arr[mid]
};


let inputList = new ListNode(1, new ListNode(2, new ListNode(3, new ListNode(4, new ListNode(5, new ListNode(6, null))))))

console.log(middleNode(inputList).val)

//================v2要点总结===============
/**
 * 1. 借助额外空间，空间复杂度O(n),时间复杂度O(n)
 */